package UseIO.UseBufferedInOutStream;

import java.io.*;
import java.util.Arrays;

public class BufferReadWrite {
    public static void main(String[] args)throws IOException {
        //method01();
        //method02();
        method03();
    }
    public static void method01() throws IOException {
        FileReader fr = new FileReader("8.内置模块/UseIO/a.txt");
        int b;
        char[] arr = new char[2];
        while ((b=fr.read(arr))!=-1){
            // 字符串的构造函数可以转换char数组
            System.out.println(new String(arr,0,b));
        }

    }
    // bufferReader
    public static void method02() throws IOException{
        BufferedReader br = new BufferedReader(new FileReader("8.内置模块/UseIO/a.txt"));
        String s;
        // 读取不到数据就返回null
        while ((s=br.readLine())!=null){
           System.out.println(s);
       }
        br.close();
    }

    public static void method03() throws IOException{
        BufferedWriter bw = new BufferedWriter(new FileWriter("8.内置模块/UseIO/b.txt"));
        bw.write("我的身体有点难受");
        bw.newLine();
        bw.write("你知道这种感觉吗");
        bw.close();
    }

}
